package com.tan.common.tools;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tan.common.mapstruct.BaseConvert;

import java.util.List;

/**
 * @author Tan-Bowen
 * @description
 * @date 2025/2/18 16:09
 */
public class PageTool {

    public static <T, S, C extends BaseConvert<T, S>> IPage<T> convert(IPage<S> page, Class<C> cls) {
        List<S> list = page.getRecords();
        List<T> res = ConvertTool.toTarget(cls, list);
        IPage<T> result = new Page<>();
        result.setRecords(res);
        result.setCurrent(page.getCurrent());
        result.setTotal(page.getTotal());
        result.setSize(page.getSize());
        return result;
    }
}
